package customer

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"server/global"
	"server/model/common/response"
	customerReq "server/model/customer/request"
	"server/utils"
)

// GetCustomerSummary  获取客户分析所需的数据，对应dashboard页面
func (ca *CustomerApi) GetCustomerSummary(c *gin.Context) {
	if list, err := customerService.GetCustomerSummary(); err != nil {
		response.FailWithMessage("获取失败", c)
		global.TD27_LOG.Error("获取客户列表失败", zap.Error(err))
	} else {
		response.OkWithDetailed(response.PageResult{
			List: list,
		}, "获取成功", c)
	}
}

// GetEnvData  获取环境列表
func (ca *CustomerApi) GetEnvData(c *gin.Context) {
	var EnvDataSp customerReq.TimeSearchParams
	EnvDataSp.StartTime, _ = utils.StringToInt64(c.Query("startTime"))
	EnvDataSp.EndTime, _ = utils.StringToInt64(c.Query("endTime"))

	if list, err := customerService.GetEnvData(EnvDataSp); err != nil {
		msg := fmt.Sprintf("获取失败,error: %s", err)
		response.FailWithMessage(msg, c)
		global.TD27_LOG.Error(msg, zap.Error(err))
	} else {
		response.OkWithDetailed(response.PageResult{
			List: list,
		}, "获取成功", c)
	}
}

// GetOnesData 获取ones的工单数据
func (ca *CustomerApi) GetOnesData(c *gin.Context) {
	var Sp customerReq.TimeSearchParams
	Sp.StartTime, _ = utils.StringToInt64(c.Query("startTime"))
	Sp.EndTime, _ = utils.StringToInt64(c.Query("endTime"))

	if list, err := customerService.GetOnesData(Sp); err != nil {
		msg := fmt.Sprintf("获取失败,error: %s", err)
		response.FailWithMessage(msg, c)
		global.TD27_LOG.Error(msg, zap.Error(err))
	} else {
		response.OkWithDetailed(response.PageResult{
			List: list,
		}, "获取成功", c)
	}
}
